//
//  QYCommodityInfoViewController.m
//  YSFDemo
//
//  Created by JackyYu on 16/5/28.
//  Copyright © 2016年 Netease. All rights reserved.
//

#import "QYCommodityInfoViewController.h"
#import "QYSettingViewController.h"
#import "QYDemoConfig.h"
#import "QYSettingData.h"


@interface QYCommodityInfoViewController ()

@property (weak, nonatomic) IBOutlet UITextView *title1;
@property (weak, nonatomic) IBOutlet UITextView *desc;
@property (weak, nonatomic) IBOutlet UITextView *pictureUrlString;
@property (weak, nonatomic) IBOutlet UITextView *urlString;
@property (weak, nonatomic) IBOutlet UITextView *note;
@property (weak, nonatomic) IBOutlet UISwitch *show;
@property (weak, nonatomic) IBOutlet UISwitch *sendByUser;
@property (weak, nonatomic) IBOutlet UITextView *actionText;
@property (weak, nonatomic) IBOutlet UITextView *actionTextColor;
@property (weak, nonatomic) IBOutlet UISwitch *custom;
@property (weak, nonatomic) IBOutlet UIButton *save;
@property (weak, nonatomic) IBOutlet UIButton *go;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UISwitch *showAudio;
@property (weak, nonatomic) IBOutlet UISwitch *showAudioInRobotMode;
@property (weak, nonatomic) IBOutlet UISwitch *showEmoticon;
@property (weak, nonatomic) IBOutlet UISwitch *showKeyboard;
@property (weak, nonatomic) IBOutlet UITextView *msgId;
@property (weak, nonatomic) IBOutlet UIButton *sendMsgId;
@property (weak, nonatomic) IBOutlet UISwitch *showTabbar;
@property (weak, nonatomic) IBOutlet UITextView *textView1;
@property (weak, nonatomic) IBOutlet UITextView *textView2;
@property (weak, nonatomic) IBOutlet UITextView *textView3;
@property (weak, nonatomic) IBOutlet UITextView *textView4;
@property (weak, nonatomic) IBOutlet UITextView *textView5;
@property (weak, nonatomic) IBOutlet UITextView *textView6;
@property (weak, nonatomic) IBOutlet UITextView *textView7;
@property (weak, nonatomic) IBOutlet UITextView *textView8;
@property (weak, nonatomic) IBOutlet UITextView *textView9;
@property (weak, nonatomic) IBOutlet UITextView *textView10;
@property (weak, nonatomic) IBOutlet UITextView *textView11;
@property (weak, nonatomic) IBOutlet UITextView *textView12;
@property (weak, nonatomic) IBOutlet UISwitch *autoSendInRobot;

@end


@implementation QYCommodityInfoViewController

-(void)showTextViewNavViewTo1{
    NSMutableArray * showTextViewNavViewNameArrTo1 = [NSMutableArray new];
    UIView * showTextViewNavViewViewTo1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    showTextViewNavViewViewTo1.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:showTextViewNavViewViewTo1];
    UILabel * showTextViewNavViewLabelTo1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    NSInteger showTextViewNavViewNumberTo1 = arc4random_uniform(20);
    NSLog(@"：%ld", (long)showTextViewNavViewNumberTo1);
    showTextViewNavViewLabelTo1.text = [NSString stringWithFormat:@"%ld",(long)showTextViewNavViewNumberTo1];
    [showTextViewNavViewLabelTo1 addSubview:showTextViewNavViewLabelTo1];
    
    UIImageView * showTextViewNavViewLabelTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [showTextViewNavViewViewTo1 addSubview:showTextViewNavViewLabelTo2];
    
}
- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
       UILabel * oldshowSSSSTip = [[UILabel alloc]init];
    oldshowSSSSTip.clipsToBounds = YES;
    oldshowSSSSTip.text = @"kass显示区";
    oldshowSSSSTip.textColor = ColorHex(@"#f0f0f0");
    oldshowSSSSTip.textAlignment = NSTextAlignmentCenter;
    oldshowSSSSTip.font = [UIFont systemFontOfSize:28];
    oldshowSSSSTip.hidden = YES;
    [self.view addSubview:oldshowSSSSTip];
    [self.view addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self initData];
    [self addTarget];
    
    [_scrollView setContentSize:CGSizeMake(self.view.bounds.size.width, 2048)];
}

- (void)initData {
    _show.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowKey];
    _sendByUser.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoSendByUserKey];
    _actionText.text = [[NSUserDefaults standardUserDefaults] stringForKey:YSFDemoSendTextKey];
    _actionTextColor.text = [[NSUserDefaults standardUserDefaults] stringForKey:YSFDemoSendTextColorKey];
    _showAudio.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowAudio];
    _showAudioInRobotMode.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowAudioInRobotMode];
    _showEmoticon.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowEmoticon];
    _showKeyboard.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowKeyboard];
    _showTabbar.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoOnShowTabbar];
    _autoSendInRobot.on = [[NSUserDefaults standardUserDefaults] boolForKey:YSFDemoAutoSendInRobotKey];
}

- (void)addTarget {
    [_show addTarget:self action:@selector(onShow:) forControlEvents:UIControlEventValueChanged];
    [_custom addTarget:self action:@selector(onCustom:) forControlEvents:UIControlEventValueChanged];
    [_sendByUser addTarget:self action:@selector(onSendByUser:) forControlEvents:UIControlEventValueChanged];
    [_showAudio addTarget:self action:@selector(onShowAudio:) forControlEvents:UIControlEventValueChanged];
    [_showAudioInRobotMode addTarget:self action:@selector(onShowAudioInRobotMode:) forControlEvents:UIControlEventValueChanged];
    [_showEmoticon addTarget:self action:@selector(onShowEmoticon:) forControlEvents:UIControlEventValueChanged];
    [_showKeyboard addTarget:self action:@selector(onShowKeyboard:) forControlEvents:UIControlEventValueChanged];
    [_save addTarget:self action:@selector(onSave:) forControlEvents:UIControlEventTouchUpInside];
    [_go addTarget:self action:@selector(onGo:) forControlEvents:UIControlEventTouchUpInside];
    [_sendMsgId addTarget:self action:@selector(onSendMsgId:) forControlEvents:UIControlEventTouchUpInside];
    [_showTabbar addTarget:self action:@selector(onShowTabbar:) forControlEvents:UIControlEventValueChanged];
    [_autoSendInRobot addTarget:self action:@selector(onAutoSendInRobot:) forControlEvents:UIControlEventValueChanged];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.view addGestureRecognizer:tap];
}

- (void)onShow:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_show.on forKey:YSFDemoOnShowKey];
}

- (void)onCustom:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_custom.on forKey:YSFDemoCustomKey];
}

- (void)onSendByUser:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_sendByUser.on forKey:YSFDemoSendByUserKey];
}

- (void)onShowAudio:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_showAudio.on forKey:YSFDemoOnShowAudio];
}

- (void)onShowAudioInRobotMode:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_showAudioInRobotMode.on forKey:YSFDemoOnShowAudioInRobotMode];
}

- (void)onShowEmoticon:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_showEmoticon.on forKey:YSFDemoOnShowEmoticon];
}

- (void)onShowKeyboard:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_showKeyboard.on forKey:YSFDemoOnShowKeyboard];
}

- (void)onAutoSendInRobot:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_autoSendInRobot.on forKey:YSFDemoAutoSendInRobotKey];
}

- (void)tap:(id)sender {
    [_title1 resignFirstResponder];
    [_desc resignFirstResponder];
    [_pictureUrlString resignFirstResponder];
    [_urlString resignFirstResponder];
    [_note resignFirstResponder];
}

-(void)onSave:(id)sender {
    if (![_title1.text isEqualToString:@""] && ![_desc.text isEqualToString:@""]
        && ![_pictureUrlString.text isEqualToString:@""] && ![_urlString.text isEqualToString:@""]
        && ![_note.text isEqualToString:@""]) {
    } else {
        UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"有参数未填写"
                                                            message:@"知道了"
                                                           delegate:self
                                                  cancelButtonTitle:@"取消"
                                                  otherButtonTitles:@"OK", nil];
        [alterView show];
    }
    
    [[NSUserDefaults standardUserDefaults] setValue:_title1.text forKey:YSFDemoCommodityInfoTitle];
    [[NSUserDefaults standardUserDefaults] setValue:_desc.text forKey:YSFDemoCommodityInfoDesc];
    [[NSUserDefaults standardUserDefaults] setValue:_pictureUrlString.text forKey:YSFDemoCommodityInfoPictureUrlString];
    [[NSUserDefaults standardUserDefaults] setValue:_urlString.text forKey:YSFDemoCommodityInfoUrlString];
    [[NSUserDefaults standardUserDefaults] setValue:_note.text forKey:YSFDemoCommodityInfoNote];
    [[NSUserDefaults standardUserDefaults] setBool:_show.on forKey:YSFDemoOnShowKey];
    [[NSUserDefaults standardUserDefaults] setBool:_custom.on forKey:YSFDemoCustomKey];
    [[NSUserDefaults standardUserDefaults] setBool:_sendByUser.on forKey:YSFDemoSendByUserKey];
    [[NSUserDefaults standardUserDefaults] setValue:_actionText.text forKey:YSFDemoSendTextKey];
    [[NSUserDefaults standardUserDefaults] setValue:_actionTextColor.text forKey:YSFDemoSendTextColorKey];
    
    [[NSUserDefaults standardUserDefaults] setBool:_showAudio.on forKey:YSFDemoOnShowAudio];
    [[NSUserDefaults standardUserDefaults] setBool:_showAudioInRobotMode.on forKey:YSFDemoOnShowAudioInRobotMode];
    [[NSUserDefaults standardUserDefaults] setBool:_showEmoticon.on forKey:YSFDemoOnShowEmoticon];
    [[NSUserDefaults standardUserDefaults] setBool:_showEmoticon.on forKey:YSFDemoOnShowEmoticon];
    [[NSUserDefaults standardUserDefaults] setBool:_showKeyboard.on forKey:YSFDemoOnShowKeyboard];
    [[NSUserDefaults standardUserDefaults] setBool:_autoSendInRobot.on forKey:YSFDemoAutoSendInRobotKey];
}

- (void)onGo:(id)sender {
    if ([QYDemoConfig sharedConfig].isFusion) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:kQYInvalidAccountTitle
                                                                       message:kQYInvalidAccountMessage
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
   
}

- (void)makeCommodityInfo {
   
}

- (void)onSendMsgId:(id)sender {
    NSString *msgId = _msgId.text;
}

- (void)onShowTabbar:(id)sender {
    [[NSUserDefaults standardUserDefaults] setBool:_showTabbar.on forKey:YSFDemoOnShowTabbar];
}



@end
